//
//  VRMessageViewController.swift
//  VoiceRoom
//
//  Created by Rae on 2024/3/11.
//

import UIKit

class VRMessageViewController: VRBaseViewController {

    private let titleLabel = c_make_ex(UILabel.self)
        .font(24.font_bold).color(.white)
        .text("Messages").end()
    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.backgroundColor = .clear
        tableView.tableFooterView = UIView(frame: .zero)
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.rowHeight = 80
        tableView.register(MessageListCell.self)
        return tableView
    }()
    private let emptyView = VRNewsEmptyView()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.subviews{
            titleLabel
            tableView
            emptyView
        }
        
        titleLabel.leading(15).top(.statusHeight + 7.5)
        tableView.leading(0).trailing(0).bottom(.tabBar_height)
        tableView.Top == titleLabel.Bottom + 5
        emptyView.top(.navi_height + 100).leading(0).trailing(0).height(180)
        emptyView.isHidden = true
    }
    
}

extension VRMessageViewController: UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.cell(MessageListCell.self, indexPath: indexPath)

        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
//        let detailVC = VRStoryDetailViewController()
//
//        self.navigationController?.pushViewController(detailVC, animated: true)
    }
    
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {

        return .delete
    }
    
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        
        let delAction = UIContextualAction(style: .normal, title: "") { [weak self] (action, view, resultClosure) in
//            guard self != nil else {
//                return
//            }
//            let model = self?.messages[indexPath.row]
//            self?.chat.deleteConversation(model?.easeUserID ?? "0")
//            self?.messages.remove(at: indexPath.row)
//            self?.tableView.reloadData()
        }
        delAction.backgroundColor = "#EB1B1B".toColor
        delAction.image = "Message_delete".toImage
        let actions = UISwipeActionsConfiguration(actions: [delAction])
        actions.performsFirstActionWithFullSwipe = false
        return actions
    }
}
